import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('../imgs/img_hist.png', 0)
hist = cv2.calcHist([img], [0], None, [256], [0, 256])  # 性能：0.025288 s


equ = cv2.equalizeHist(img)
clahe = cv2.createCLAHE(clipLimit=5.0, tileGridSize=(8, 8))
cl1 = clahe.apply(img)

cv2.namedWindow('equalization', cv2.WINDOW_NORMAL)
cv2.imshow('equalization', np.hstack((img, equ, cl1)))  # 并排显示
cv2.waitKey(1000)


plt.subplot(1, 3, 1)
plt.hist(img.ravel(), 256, [0, 256])
plt.subplot(1, 3, 2)
plt.hist(equ.ravel(), 256, [0, 256])
plt.subplot(1, 3, 3)
plt.hist(cl1.ravel(), 256, [0, 256])
plt.show()
